﻿using A.M.Storage.Application;
using A.M.Storage.I_Infrastruecure;
using O.M.Production.Application.IService;
using O.M.Production.Domain.Entity;
using O.M.Production.ErrorCodeEnum;
using O.M.Production.Infrastuecure.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;

namespace O.M.Production.Application.Service
{
    /// <summary>
    /// 工艺流程服务接口实现类
    /// </summary>
    public class process_flow_Service : BaseServices<process_flow, string>,I_process_flow_Service
    {
        private readonly I_process_flow_Repository _process_Flow_Repository;
        public process_flow_Service(I_process_flow_Repository process_Flow_Repository) : base(process_Flow_Repository)
        {
            _process_Flow_Repository = process_Flow_Repository;
        }

        /// <summary>
        /// 分页查询显示-工艺流程
        /// </summary>
        /// <param name="process_flow_id_name">工艺流程编号或者名称</param>
        /// <param name="pageSize">页容量</param>
        /// <param name="pageIndex">页码</param>
        /// <returns>统一返回格式</returns>
        public async Task<ApiResult> Get_process_flow_Page(string? process_flow_id_name, int pageSize, int pageIndex)
        {
            try
            {
                ApiResult apiResult = new ApiResult();
                Expression<Func<process_flow, bool>> whereidname = i => true;
                if (!string.IsNullOrEmpty(process_flow_id_name))
                {
                    whereidname = i => i.process_flow_id.Contains(process_flow_id_name) || i.process_flow_name.Contains(process_flow_id_name);
                }
                var list=await _process_Flow_Repository.GetShowInforAsync(pageSize, pageIndex,whereidname);
                apiResult.totalCount = list.TotalCount;
                apiResult.pageCount= list.PageCount;
                apiResult.Data=list.Data.OrderByDescending(x=>x.process_flow_id).ToList();
                return apiResult;
            }
            catch (Exception)
            {

                throw;
            }
        }
    }
}
